/*
 * AS_EMERGENCY_NOTICE.cpp
 *
 *  Created on: 2013. 12. 5.
 *      Author: mega
 */

#include "../../User.h"
#include "../../Command.h"
#include "../../Proxy.h"
#include <Toolkit/Str.h>

namespace ProjectZ { namespace NCommand {

void Command::AS_EMERGENCY_NOTICE(User * pUser, ::Network::Packet * pPacket)
{
	PREPARE_PACKET;

	Toolkit::Str<512> message;
	*pPacket >> message;

	Toolkit::Str<1024> emergency = "!cff0000";
	emergency.Append(message.c_str(), message.SIZE());

	DEBUGLOG("EMERGENCY LOG = %s", message.c_str());

	auto iter = NProxy::GetUserTree().begin();

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	*pAck << emergency.c_str();
	pAck->MakePacket(CMD_SC_EMERGENCY_NOTICE);

	for (; iter != NProxy::GetUserTree().end(); ++iter)
	{
		iter->second->SendOneshotEncrypt(pAck);
	}
	::Network::GETPACKETPOOL()->SEND_DEL(pAck);
}

} /*NCommand*/ } /*ProjectZ*/
